<?php

namespace App\Http\Controllers\Wechat;

use App\Http\Controllers\Controller;
use App\Http\Controllers\LibApi\CdbtResourceController;
use App\Models\ResourceCdbt;
use App\Models\ResourceYtys;
use App\Models\ResourceZwzx;
use App\Validate\ResourceTotalCdbtValidate;

/**
 * 之间数字阅读统一管理(对接外部资源)
 */
class ResourceTotalController extends Controller
{
    public $model = null;
    public $validate = null;

    public function __construct()
    {
        parent::__construct();

        $this->model = new ResourceCdbt();
        $this->validate = new ResourceTotalCdbtValidate();
    }


    /**
     * 获取电子图书章节
     * @param guid  资源guid
     * @param resource_business_id  资源商id
     */
    public function getEbookBookChapter()
    {
        //增加验证场景进行验证
        if (!$this->validate->scene('wx_get_ebook_book_chapter')->check($this->request->all())) {
            return $this->returnApi(201,  $this->validate->getError());
        }
        if ($this->request->resource_business_id != 999) {
            return $this->returnApi(203, '暂无数据'); //目前只有1的才能获取目录
        }
        $model = new CdbtResourceController();
        $res = $model->getResourceChapter($this->request->guid);
        if ($res) {
            return $this->returnApi(200, "获取成功", true, $res);
        }
        return $this->returnApi(203, '暂无数据');
    }

    /**
     * 获取云图有声章节音频地址
     * @param resource_business_id  资源商id
     * @param chapter_id 章节id
     */
    public function getYtysChapterAudioAddress()
    {
        //增加验证场景进行验证
        if (!$this->validate->scene('get_ytys_chapter_audio_address')->check($this->request->all())) {
            return $this->returnApi(201,  $this->validate->getError());
        }
        if ($this->request->resource_business_id != 3) {
            return $this->returnApi(203, '暂无数据'); //目前只有1的才能获取目录
        }
        $model = new ResourceYtys();
        $res = $model->getYtysChapterAudioAddress($this->request->chapter_id);
        if ($res) {
            return $this->returnApi(200, "获取成功", true, $res);
        }
        return $this->returnApi(203, '暂无数据');
    }

    /**
     * 获取中文在线单点登录信息
     * @param token 用户token
     * @param guid  资源guid
     * @param resource_business_id  资源商id
     */
    public function getZwzxSingleSign()
    {
        //增加验证场景进行验证
        if (!$this->validate->scene('wx_get_zwzx_single_sign')->check($this->request->all())) {
            return $this->returnApi(201,  $this->validate->getError());
        }
        if ($this->request->resource_business_id != 1) {
            return $this->returnApi(203, '暂无数据'); //目前只有1的才能获取目录
        }
        $model = new ResourceZwzx();
        $res = $model->getZwzxSingleSign($this->request->token, $this->request->guid);
        if ($res) {
            return $this->returnApi(200, "获取成功", true, $res);
        }
        return $this->returnApi(203, '暂无数据');
    }
}
